#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>

using namespace std;

// 基类 Animal
class Animal {
public:
    string name;

    Animal(string name) : name(name) {}

    virtual void makeSound() const = 0; // 纯虚函数
};

// 子类 Tiger
class Tiger : public Animal {
public:
    Tiger(string name) : Animal(name) {}

    void makeSound() const override {
        cout << "Tiger: Roar!" << endl;
    }
};

// 子类 Elephant
class Elephant : public Animal {
public:
    Elephant(string name) : Animal(name) {}

    void makeSound() const override {
        cout << "Elephant: Trumpet!" << endl;
    }
};

// 子类 Fox
class Fox : public Animal {
public:
    Fox(string name) : Animal(name) {}

    void makeSound() const override {
        cout << "Fox: Chirp!" << endl;
    }
};

// 子类 Panda
class Panda : public Animal {
public:
    Panda(string name) : Animal(name) {}

    void makeSound() const override {
        cout << "Panda: Squeak!" << endl;
    }
};

int main() {
    srand(static_cast<unsigned int>(time(NULL))); // 初始化随机数发生器

    vector<Animal*> animals(10); // 创建一个长度为10的动物数组
    for (size_t i = 0; i < animals.size(); ++i) {
        int randomAnimal = rand() % 4; // 随机选择一种动物
        switch (randomAnimal) {
            case 0:
                animals[i] = new Tiger(string("Tiger"));
                break;
            case 1:
                animals[i] = new Elephant(string("Elephant"));
                break;
            case 2:
                animals[i] = new Fox(string("Fox"));
                break;
            case 3:
                animals[i] = new Panda(string("Panda"));
                break;
        }
    }

    for (Animal* animal : animals) {
        animal->makeSound();
    }

    // 清理动态分配的内存
    for (Animal* animal : animals) {
        delete animal;
    }

    return 0;
}
